/**
 * Theme live preview style switcher.
*/

jQuery(document).ready(function($) {

	$('#mtp-toggle').click(function(){
		$('#mtp-wrapper').toggle();
		$('#mtp-toggle').toggleClass('mtp-toggle-close');
	});
	
	$('#mtp-toggle').click();
	
	$('.mtp-layout-select').change(function(){
		var currentClass = $('#layout-wrapper').attr('class');
		$('#layout-wrapper').removeClass(currentClass).addClass($(this).val());
		currentClass = $(this).val();
		$(window).trigger('resize');
	});
	
	$('.mtp-primary-color').click(function(){
		$('.iris-picker').toggle();
	});
		
	$('.mtp-color-field').iris({
		palettes: true,
		border: false,
		width: 155,
		color: '#f86b35',
		mode: 'hsl',
		palettes: ['#e34461', '#32a0c2', '#82bc1e', '#c01a1a', '#f6bb17', '#54737c'],
		change: function(event, ui) {
			$('.for-preview, .quote-start, .wp-pagenavi span.current, .service-box i, .person-title, .quote-author, .tp-caption.kickstart_color, .widget_side_menu  ul li.current-menu-item a').css( 'color', ui.color.toString());
			
			
			$('.su-button, .sidebar-line span, .background-block, .latest-blog-entry .blog-entry-date span, #wp-calendar #today, #footer-widget-area #wp-calendar tbody td#today, .link-button a, .wpcf7-submit, .post-link, .mtp-primary-color, #mtp-toggle, .skillbar, thead th, input[type="submit"], .tp-caption.kickstart_button, .tp-caption.kickstart_bgcolor, #header-search-wrapper').css( 'background-color', ui.color.toString());	
					
			$('.su-pullquote-style-1, .wp-pagenavi span.current').css( 'border-color', ui.color.toString());
			
			$('.for-preview, #primary-main-menu > li.current-menu-item, #primary-main-menu > li.current-menu-ancestor, #primary-main-menu > li.current_page_parent').css( 'border-bottom-color', ui.color.toString());
			
			$('.su-callout').css( 'border-left-color', ui.color.toString());
			
			$('.latest-works ul li .pf-title, .filterable-grid li a.pf-info, .filterable-grid li a.pf-zoom, .filterable-grid .pf-title, .fp_carousel li .fp_title').css( 'background-color', ui.color.toCSS('rgb', 0.8));
			
			/* Hover fix */			
			$('head').append('<style type="text/css">#primary-main-menu li ul li:hover > a, #primary-main-menu li ul > li.current-menu-item > a, #primary-main-menu li ul > li.current-menu-ancestor > a, #primary-main-menu li ul > li.ccurrent_page_parent > a, a:hover, #footer-widget-area a:hover, .entry-utility a:hover, .wp-pagenavi a:hover, .su-tabs-nav span:hover .su-tab-icon, .su-tabs .pane-wrapper .pane-title:hover .su-tab-icon, .su-tabs .pane-wrapper .pane-title.su-tabs-current .su-tab-icon, .su-tabs-nav span.su-tabs-current .su-tab-icon, .su-spoiler-title:hover .spoiler-button, #copyright a:hover, .su-spoiler-title .spoiler-button.spoiler-active, .su-fancy-link:hover, .fp_carousel .jcarousel-prev:hover, .fp_carousel .jcarousel-next:hover, #footer-menu a:hover, ul.pf-filter li.active a {color:'+ ui.color.toString() +'} .nivo-directionNav a:hover, .nivo-controlNav a.active {background-color:'+ ui.color.toString() +'} .wp-pagenavi a:hover, .wp-pagenavi span.current, ul.pf-filter li.active, #primary-main-menu > li:hover > a{border-color:'+ ui.color.toString() +'} .nivo-directionNav a:hover, .nivo-controlNav a.active {background-color:'+ ui.color.toString() +'} #primary-main-menu > li.current-menu-item > a:after, #primary-main-menu > li.current-menu-ancestor > a:after, #primary-main-menu > li.current_page_parent > a:after, #primary-main-menu li.search-active a, #header-search-wrapper:before {border-bottom-color:'+ ui.color.toString() +'}</style>');

			
			/* Background fix */
			$('.mtp-off .background-block').css( 'background-color', '#f7f7f7');
			
			/* Woocommerce */
			$('.woocommerce div.product span.price,.woocommerce div.product p.price,.woocommerce #content div.product span.price,.woocommerce #content div.product p.price,.woocommerce-page div.product span.price,.woocommerce-page div.product p.price,.woocommerce-page #content div.product span.price,.woocommerce-page #content div.product p.price, .woocommerce ul.products li.product .price,.woocommerce-page ul.products li.product .price, .woocommerce .cart-collaterals .cart_totals table .total th, .woocommerce .cart-collaterals .cart_totals table .total td, .woocommerce table.shop_table tfoot .total td,.woocommerce table.shop_table tfoot .total th').css( 'color', ui.color.toString());
			
			$('.woocommerce a.button,.woocommerce button.button,.woocommerce input.button,.woocommerce #respond input#submit,.woocommerce #content input.button,.woocommerce-page a.button,.woocommerce-page button.button,.woocommerce-page input.button,.woocommerce-page #respond input#submit,.woocommerce-page #content input.button, .woocommerce span.onsale,.woocommerce-page span.onsale, .woocommerce a.button.alt,.woocommerce button.button.alt,.woocommerce input.button.alt,.woocommerce #respond input#submit.alt,.woocommerce #content input.button.alt,.woocommerce-page a.button.alt,.woocommerce-page button.button.alt,.woocommerce-page input.button.alt,.woocommerce-page #respond input#submit.alt,.woocommerce-page #content input.button.alt, .woocommerce .widget_price_filter .ui-slider .ui-slider-handle,.woocommerce-page .widget_price_filter .ui-slider .ui-slider-handle').css( 'background-color', ui.color.toString());
		}
	});
	
});